package com.assignwork.dto;

import com.assignwork.entity.AssemblyLine;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * AssemblyLineDTO
 */
@Data
@ApiModel(value = "AssemblyLineDTO对象", description = "作业线")
public class AssemblyLineDTO extends AssemblyLine {

    public static final String SHIFT_KEY_DAY = "DAY";

    private List<JobConfigDTO> jobConfig;
    private List<List<StartedCabinDTO>> startedCabin;
    private List<StartedCabinDTO> allStartedCabin;
    private List<Long> jobConfigId;
    private List<Long> startedCabinId;

    public List<JobConfigDTO> getJobConfig() {
        if (getId() != null) {
            Long id = getId();
            Long planId = getPlanId();
            return jobConfig.stream().map(i -> {
                i.setLineId(id);
                i.setPlanId(planId);
                return i;
            }).collect(Collectors.toList());
        }
        return jobConfig;
    }

    public List<StartedCabinDTO> getAllStartedCabin() {
        if (Func.isNotEmpty(startedCabin)) {
            Long id = getId();
            List<StartedCabinDTO> res = new ArrayList<>();
            for (int i = 0; i < startedCabin.size(); i++) {
                List<StartedCabinDTO> ls = startedCabin.get(i);
                String s = i + Func.randomUUID();
                for (StartedCabinDTO hatch : ls) {
                    if (Func.isBlank(hatch.getGroupFg())) {
                       hatch.setGroupFg(s);
                    }
                    if (id != null) {
                        hatch.setLineId(id);
                    }
                    res.add(hatch);
                }
            }
            return res;
        }
        return allStartedCabin;
    }
}